<template>
  <basic-container>
    <el-dialog
      title="毕业生一卡通余额管理" :visible.sync="dialog" append-to-body height="450" width="80%" @close="cancelDialog">
    <div class="container-body">
      <div class="cap-tmpl-new">
        <div class="row">
          <div class="row-box rowbj">
            <el-form :inline="true" :model="query" class="demo-form-inline" label-width="100px" style="margin-top: 20px;" >
              <el-form-item label="毕业年份">
                <el-date-picker
                  v-model="query.byYear"
                  type="year"
                  value-format="yyyy"
                  placeholder="选择年">
                </el-date-picker>
              </el-form-item>
              <el-form-item label="学院名称">
                <el-input v-model="query.xymc" size="small"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button :loading="loading" icon="el-icon-search" size="small" type="primary" @click="onSearch">统计</el-button>
                <el-button :loading="loading" icon="el-icon-delete" size="small" @click="searchReset">清空</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="row">
          <div class="row-box rowbj">
            <div class="row-title">数据指标</div>
            <div class="row-con">
              <div class="col">
                <div class="col-box">
                  <span class="cap-title" title="总人数">总人数</span>
                  <span class="cap-text-color">{{studentCount.countTotal}}</span>
                </div>
                <div class="colicon"><i class="tubiao1"></i></div>
              </div>
              <div class="col">
                <div class="col-box">
                  <span class="cap-title">已退人数</span>
                  <span class="cap-text-color">{{studentCount.countHasTotal}}</span>
                </div>
                <div class="colicon"><i class="tubiao2"></i></div>
              </div>
              <div class="col">
                <div class="col-box">
                  <span class="cap-title">未退人数</span>
                  <span class="cap-text-color">{{studentCount.countOnTotal}}</span>
                </div>
                <div class="colicon"><i class="tubiao3"></i></div>
              </div>
            </div>
          </div>
        </div>
        <div class="row-tab rowbj">
          <el-tabs v-model="activeName" @tab-click="handleClick('task')">
            <el-tab-pane label="详细数据" name="first">
              <el-table header-row-class-name="container-table-header"
                        :data="data" size="small"
                        style="width: 100%;margin-bottom: 20px;"
                        row-key="id"
                        border stripe
                        v-loading="loading">
                <el-table-column prop="xh" label="学号">
                </el-table-column>
                <el-table-column prop="xm" label="姓名">
                </el-table-column>
                <el-table-column prop="xymc" label="学院名称">
                </el-table-column>
                <el-table-column prop="zymc" label="专业名称">
                </el-table-column>
                <el-table-column prop="dqzt" label="当前状态">
                </el-table-column>
                <el-table-column prop="khzh" label="卡号账户">
                </el-table-column>
                <el-table-column prop="kaye" label="卡余额">
                </el-table-column>
                <el-table-column prop="kuye" label="库余额">
                </el-table-column>
              </el-table>
              <div class="container-page">
                <el-pagination
                  @size-change="sizeChange"
                  @current-change="currentChange"
                  :current-page="page.current"
                  :page-sizes="[10, 20, 30, 40, 50, 100]"
                  :page-size="10"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="page.total">
                </el-pagination>
              </div>
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
    </div>

    </el-dialog>
  </basic-container>
</template>

<script>
import {fetchBalanceList} from "@/api/data/jwxt/xsjbxxb";
import {countStudent} from "@/api/analysis/analysis";
import {mapGetters} from "vuex";
import ExcelUpload from "@/components/upload/excel.vue";


export default {
  name: 'yktyeglView',
  props: {
    dialog: Boolean,
  },
  components: {
    ExcelUpload
  },
  dictTypes: [],
  data() {
    return {
      loading: false,
      query: {},
      page: {
        size: 10,
        current: 1,
        total: 0
      },
      studentCount: {
        countTotal: 0,
        countOnTotal: 0,
        countHasTotal: 0
      },
      data: [],
      Authorization: 'Bearer ' + this.$store.getters.access_token,
      activeName: 'first',
    }
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  methods: {
    init(){
      this.onLoad(this.page);
    },
    // 关闭
    cancelDialog() {
      this.loading = false;
      this.$emit('closeDialog', false)
    },
    handleClick(name) {
      if(name === 'task') {
        this.onLoadTask();
      }
      if(name === 'message') {
        this.onSearchMessage();
      }
    },
    resetForm() {
      this.fileList = [];
      this.fileListVideo = [];
      this.auditBox = false;
    },
    onSearch() {
      this.page.current = 1;
      // this.query.byYear = this.query.byYear.getFullYear();
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.current = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(current) {
      this.page.current = current;
      this.onLoad(this.page);
    },
    sizeChange(size) {
      this.page.size = size;
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      countStudent(this.query).then(res => {
        this.studentCount = res.data.data;
      });
      fetchBalanceList(Object.assign(params, this.query, page)).then(res => {
        this.loading = false;
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        console.log(this.data);
      }, () => {
        this.loading = false;
      });
    },
  }
};
</script>

<style scoped>
</style>
